<template>
    <view class="content">
        <u--form labelPosition="left" labelWidth="70" :model="userInfo" :rules="rules" ref="form1">
            <u-form-item label="分配人员:" prop="username" @click="show = true">
                <u--input v-model="userInfo.username" disabled disabledColor="#ffffff" placeholder="请选择"
                    suffixIcon="arrow-down">
                </u--input>
            </u-form-item>
            <u-form-item label="客户名称" prop="nickname">
                <u--input v-model="userInfo.nickname" readonly></u--input>
            </u-form-item>
        </u--form>
        <u-button @click="submit" color="#19BC9C">确认分配</u-button>
        <u-picker :show="show" :columns="adminlist" keyName="username" @cancel="show = false"
            @confirm="confirm"></u-picker>
        <u-toast ref="uToast"></u-toast>
    </view>
</template>

<script>
export default {
    onLoad(options)
    {
        this.userInfo.id = options.busid ? options.busid : 0

        this.userInfo.nickname = options.nickname ? options.nickname : ''

        this.getAdminData()
    },
    data() {
        return {
            userInfo: {
                id: 0,
                nickname: '',
                username: '',
                adminid: 0
            },
            rules: {
                'content': {
                    type: 'string',
                    required: true,
                    message: '请填写回访内容',
                    trigger: ['blur', 'change']
                }
            },
            LoginUser: {},
            adminlist: [],
            show: false
        }
    },
    methods: {
        async getAdminData()
        {
            let result = await this.$u.api.business.adminlist()

            if(result.code === 1)
            {
                this.adminlist.push(result.data)
            }
        },
        confirm(e)
        {
            let value = e.value[0]

            this.show = false

            this.userInfo.adminid = value.id

            this.userInfo.username = value.username
        },
        async submit()
        {
            let data = {
                busid:this.userInfo.id,
                adminid:this.userInfo.adminid
            }

            let result = await this.$u.api.business.highseaAllot(data)

            if(result.code === 1)
            {
                this.$refs.uToast.show({
                    type:'success',
                    message:result.msg,
                    complete:() => {
                        this.$u.route({
                            type:'redirectTo',
                            url:'/packageA/highsea/index'
                        })
                    }
                })

                return false
            }else{
                this.$refs.uToast.show({
                    type:'error',
                    message:result.msg,
                })

                return false
            }
        }
    },
}
</script>

<style>
	.content{
		width: 90%;
		height: 100vh;
		margin: 0 auto;
	}
</style>